#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
void do_ls(char *);
int main(int argc, char* argv[])
{
    if (argc == 1)
    {
        do_ls(".");
    }
    else if (argc == 2)
    {
        do_ls(argv[1]);
    }
    else
    {
        while (--argc)
        {
            printf("%s:\n", *++argv);
            do_ls(*argv);
        }
    }

    return 0;
}
void do_ls(char * path)
{
    DIR * pDir;
    struct dirent* pDirent;
    if ((pDir = opendir(path)) == NULL)
    {
        fprintf(stderr, "ls1 cannot open %s\n", path);
    }
    else
    {
        // printf("open successed\n");
        while ((pDirent = readdir(pDir)) != NULL)
        {
            printf("%s\n", pDirent->d_name);
        }
        printf("\n");
        closedir(pDir);
    }

}